package phoenics.manpads.common.auth.session;

import javax.servlet.*;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * session过滤器
 *
 * @author Phoenics Chow
 * on 2018年12月15日
 */
public class SessionFilter implements  Filter {
    private static org.slf4j.Logger logger = org.slf4j.LoggerFactory.getLogger(SessionFilter.class);

    @Override
    public void init(FilterConfig filterConfig) throws ServletException {

    }

    @Override
    public void doFilter(ServletRequest request, ServletResponse response, FilterChain filterChain) throws IOException, ServletException {
        HttpServletRequest servletRequest = (HttpServletRequest) request;
        HttpServletResponse servletResponse = (HttpServletResponse) response;
        String session_id=servletRequest.getSession().getId();
        servletResponse.setHeader("x-token",session_id);
        filterChain.doFilter(request, response);
    }

    @Override
    public void destroy() {

    }
}
